| Total Complexity | 2 |
| Total Lines | 20 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { QueryHandler } from '@nestjs/cqrs'; |
||
| 7 | |||
| 8 | @QueryHandler(GetVoucherByCodeQuery) |
||
| 9 | export class GetVoucherByCodeQueryHandler { |
||
| 10 | constructor( |
||
| 11 | @Inject('IVoucherRepository') |
||
| 12 | private readonly voucherRepository: IVoucherRepository |
||
| 13 | ) {} |
||
| 14 | |||
| 15 | public async execute({ code }: GetVoucherByCodeQuery): Promise<VoucherView> { |
||
| 16 | const voucher = await this.voucherRepository.findOneByCode(code); |
||
| 17 | |||
| 18 | if (!voucher) { |
||
| 19 | throw new VoucherNotFoundException(); |
||
| 20 | } |
||
| 21 | |||
| 22 | return new VoucherView( |
||
| 23 | voucher.getId(), |
||
| 24 | voucher.getCode(), |
||
| 25 | voucher.getEmail(), |
||
| 26 | voucher.getSchool().getId(), |
||
| 27 | ); |
||
| 30 |